will place "Hello world" in the read-only parts of the memory, and making s a pointer to that makes any writing operation on this memory illegal.
puts the literal string in read-only memory and copies the string to newly allocated memory on the stack. Thus making:
Legal.
My question is then why does Case 1 below result in Hello World! and Case 2 result in Iello World! ?
Case 1:
Code:
void getToken(char **infix) {
(*infix)++;
}
int main () {
char *myString = "Hello World!";
getToken(&myString);
printf("%s", myString);
return 0;
}
Case 2:
Code:
void getToken(char **infix) {
(*infix)++;
}
int main () {
char myString[] = "Hello World!";
getToken(&myString);
printf("%s", myString);
return 0;
}